/**
 *
 */

package com.wuye.web;


import org.json.JSONObject;

/**
 * state 命名规则:1-2Face名称， 5-6状态值
 */

// @JsonSerialize(using = STSerializer.class)
public enum ST {
    unknow(-1, "未知状态"), ok(0, ""),

    sysError(1, "系统错误"), netError(2, "网络错误"), tokenLost(3, "缺少参数token"),
    tokenInvalid(4, "token失效"), paramError(5, "参数错误"), belongError(6, "数据所属错误"),
    cumulativeNotEnough(7, "积分不够"),
    dataNotExists(9, "数据不存在"), noRule(10, "没有权限"),

    dataReaptition(11, "数据重复"), beyondMaximumLimit(12, "超过最大限制"),dataExpired(13,"数据已过期"),
    dataHasChild(14,"含有下级节点，请先删除下级节点"),

    orderStateUpdateError(15,"订单状态错误"),
    paperHasEnd(5000,"问卷答卷时间已经截至"),
    paperHasFinished(5001,"您已经答过该问卷"),

    unknowError(99, "未知错误"), //

    calendarDateError(500, "日期有冲突"), calendarInsertError(501, "插入日期失败"),
    calendarDeleteError(502, "删除日期失败"), parseDateError(503, "日期解析失败"),

    // 短信服务部分
    smsSendMax(1000, "下发短信太多"), smsSendTooFast(1001, "下发太快"),
    smsSendFail(1003, "发送短信失败"), smsGatewayError(1004, "短信网关不可用"),
    verifyCodeNotExist(1100, "认证码不存在"), verifyCodeError(1101, "认证码错误"), //
    mobileRegistered(1200, "手机号码已注册"), //

    userUnRegister(1300, "用户未注册"), userNotLogin(1301, "用户未登录"),
    userNotExist(1302, "用户不存在"), userIsBlock(1303, "用户已存在于黑名单"), userExist(1304, "用户已存在"),//

    mailRegistered(1400, "邮件已注册"),

    loginWrongPassword(1400, "密码错误"),  // ==

    groupUsersJoined(1500, "不能重复加入专区"), groupNotExist(1501, "专区不存在"), groupNotJoin(1502, "没有加入专区"),

    orderCreateFail(1601, "订单创建失败"), orderNotExist(1602, "订单不存在"),

    goodsLimitNum(1700, "商品已达到限购数量！"), goodsNumError(1701, "商品数量不正确"), goodsCannotSale(1702, "商品已经售罄！"),
    goodsNotSaleInCity(1703, "商品在此地区无货！"),goodsMaxStock(1705, "已达最大库存量！"),

    cardNotAvailable(1800, "该卡无法使用"), cardNotBind(1801, "卡未绑定"), cardExpire(1802, "卡已过期"),
    cardNotActive(1803, "卡未激活"), cardUsed(1804, "卡已使用"),


    bonusBinded(1900, "该优惠券已绑定"), bonusExpire(1901, "该优惠券已过期"), bonusUsed(1904, "该优惠券已使用"), bonusExist(1905, "该优惠券已存在"),
    bonusCannotUse(1906, "优惠券不可使用"), bonusOnce(1907, "该优惠券限领一次"),

    moneyNotEnough(2000, "账户余额不足"), consigneeError(2001, "收货人姓名错误"), addressError(2002, "收货地址错误"),

    cartEmpty(2100, "购物车数据为空"),

    productRangeError(2200, "商品范围不正确"), goodsAmountError(2201, "商品价格不正确"),

    SVCNotFind(2300, "储值卡不存在"), SVCUsed(2301, "储值卡已使用"), SVCNotActive(2302, "储值卡未激活"),
    SVCExpire(2303, "储值卡已过期"),SVCErr(2304, "储值卡卡号或密码不正确"),

    SKUBatchNotEmpty(3000, "该批次库存不为空"),SKUKeepingNotEnough(3001, "有商品库存数量不足！"),SKUNotExist(3002,"库存商品不存在"),
    //3003 -- 销售商品没有对应的库存商品
    SKUNotBind(3003, "有商品库存数量不足！"),
    StockingChangeFailed(3004, "库存数量更改失败"),

    orderHangedUp(3030, "未关联库存，订单挂起"),

    //youpin
    sysRoleError(10001, "登录的用户无此权限"),

    orderStateError(10100, "订单状态异常"), orderPayBillWayNotDefine(10101, "订单支付方式未实现"), orderFast(10102, "下单太快，臣妾做不到"),
    orderCannotCancel(10103, "此订单不能取消！"),orderNoProductDate(10104, "订单状态异常"),

    fileNotExist(10200, "文件不存在"),

    inProgress(10300,"运行中，请等待"),

    uploadFileNotSupport(30000, "上传文件格式不支持"),

    weixinException(40000, "微信出问题了"), weixinCreateCodeException(40001, "微信获取二维码出问题了"),cannotCancle(40002,"16:30之后不能取消订单"),
    cannotOrder(40003,"该时间段不支持订餐,请在营业时间段点餐");




    ST(int state, String desc) {
        this.state = state;
        this.description = desc;
    }

    public int state;
    public String description;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String toJson() {
        return "{\"code\":" + state + ",\"description\":\"" + description
                + "\"}";
    }

    public static ST getST(int st) {
        for (ST s : ST.values()) {
            if (s.state == st)
                return s;
        }
        return ST.unknow;
    }

    public JSONObject getJsonObject(Object result) {
        JSONObject json = getJsonObject();
        json.put("result", result);
        return json;
    }

    public JSONObject getJsonObject() {
        JSONObject json = new JSONObject();
        json.put("description", description);
        json.put("code", state);
        return json;
    }

    public <E> Result getResult(E e) {
        return new Result(this, e);
    }
}
